package com.mufeng.utils


/* dp/px 相关工具 */
private val density by lazy {
    context.resources.displayMetrics.density
}
/* from dp to px */
val Int.dp: Int
    get() = (density * this + 0.5f).toInt()

val Float.dp: Float
    get() = density * this + 0.5f

/* from px to dp */
val Int.toDp: Int
    get() = (this / density + 0.5f).toInt()

val Float.toDp: Float
    get() = this / density + 0.5f


/* sp/px 相关工具 */
private val scaledDensity by lazy {
    context.resources.displayMetrics.scaledDensity
}

/* from sp to px */
val Int.sp: Int
    get() = (scaledDensity * this + 0.5f).toInt()

val Float.sp: Float
    get() = scaledDensity * this + 0.5f

/* from px to sp */
val Int.toSp: Int
    get() = (this / scaledDensity + 0.5f).toInt()

val Float.toSp: Float
    get() = this / scaledDensity + 0.5f
